package br.com.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;

public class Conecta {

    private static Connection con = null;
    
//      public final static String DRIVER = "com.mysql.jdbc.Driver";  
//      public final static String URL = "jdbc:mysql://192.168.236/unirc";  
//      public final static String USER = "useroot";  
//      public final static String PASSWD = "1a2b*";  
    
    public final static String DRIVER = "com.mysql.jdbc.Driver";
    public final static String URL = "jdbc:mysql://localhost:3306/zero_unirc";
    public final static String USER = "root";
    public final static String PASSWD = "";

    public Conecta() {
        if (con == null) {
            loadDriver();
        }
    }

    public static void loadDriver() {
        try {
            Class.forName(DRIVER);
            con = DriverManager.getConnection(URL, USER, PASSWD);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "FALHA NA CONEXÃO");
            e.printStackTrace();
        }
    }

    public static Connection getConnection() {
        if (con == null) {
            loadDriver();
        }
        return con;
    }

    public static void erroDB() {
        con = null;
    }
}
